﻿using AutoMapper;
using B.S.Ingredients.APIRead.Application.Command.Cuitva;
using B.S.Ingredients.APIRead.Application.Command.EnterCommand;
using B.S.Ingredients.APIRead.Application.Command.Imginfors;
using B.S.Ingredients.APIRead.Application.Command.ImmunityCommand;
using B.S.Ingredients.APIRead.Application.Command.Over;
using B.S.Ingredients.APIRead.Application.Command.Products;
using B.S.Ingredients.APIRead.Application.Command.SlanBoss;
using B.S.Ingredients.APIRead.Application.Command.SlaughterCommand;
using B.S.Ingredients.APIRead.Application.CommandHandler.Imginforsa;
using B.S.Ingredients.APIRead.DTOs;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Impment;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using System.Text;

namespace B.S.Ingredients.APIRead.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShopsController : ControllerBase
    {
        public ShopsController(IMediator mediator,ILogger<ShopsController> logger)
        {
            Mediator = mediator;
            Logger = logger;
        }

        public IMediator Mediator { get; }
        public ILogger<ShopsController> Logger { get; }
        [HttpGet]
        public async Task<APIResult<APIPageing<List<ProductDTO>>>> ProduQuert([FromQuery]ProdictQueryCommand request )
        {
            Logger.LogInformation("查询商品信息成功");
          return await Mediator.Send(request);
        }

        [HttpPost]
        public async Task<APIResult<int>> ShopsCreate(ProductCreateCommand request)
        {
            Logger.LogInformation("新增商品信息成功");
            return await Mediator.Send(request);
        }

        [HttpPost]

        public IActionResult ProduQueryImg(IFormFile file)
        {
            Logger.LogInformation("上传图片成功");
            var n=Guid.NewGuid();
            var files="wwwroot/Img/"+n+file.FileName;

            using (FileStream fs=new FileStream(files,FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            var path = "http://localhost:27167/Img/" + n + file.FileName;
            return Ok(path);
        }
        [HttpGet]
        public async Task<APIResult<List<ProduciNameClass>>> ProduciQuery([FromQuery]ProdictNameQueryCommand request )
        {
            Logger.LogInformation("查询商品名称成功");
            return await Mediator.Send(request);
        }
        [HttpDelete]
        public async Task<APIResult<int>> ProduciDel([FromQuery]ProductDelCommand request )
        {
            Logger.LogInformation("删除商品信息成功");
            return await Mediator.Send(request);
        }
        [HttpPut]
        public async Task<APIResult<int>> ProducUpdate(ProdictUpdateCommand request )
        {
            Logger.LogInformation("修改商品信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<ProductDTO>> ProductFt([FromQuery]ProdictFtCommand request  )
        {
            Logger.LogInformation("反填商品信息成功");
            return await Mediator.Send(request);
        }

        [HttpPost]

        public async Task<APIResult<int>> CuitvaCreate(CuitvaCreateCommand request )
        {
            Logger.LogInformation("新增养殖信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<CuitvaClass>> CuitvaQuery([FromQuery]CuitvaFtCommand request )
        {
            Logger.LogInformation("反填养殖信息成功");
            return await Mediator.Send(request);
        }
        [HttpPost]
        public async Task<APIResult<int>> ImmunitCreate(ImmunitCreateCommand request )
        {
            Logger.LogInformation("新增保健信息成功");
            return await Mediator.Send(request);
        }
        [HttpPut]
        public async Task<APIResult<int>> ImminitUpdate(ImmunitUpdateCommand request )
        {
            Logger.LogInformation("修改保健信息成功");
            return await Mediator.Send(request);
        }
        [HttpDelete]
        public async Task<APIResult<int>> ImminitDelete([FromQuery]ImmunitDeleteCommand request )
        {
            Logger.LogInformation("删除保健信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<List<Immunity>>> ImminitQuery([FromQuery]ImmunitFtCommand request )
        {
            Logger.LogInformation("反填保健信息成功");
            return await Mediator.Send(request);
        }

        [HttpPost]

        public IActionResult MyImg( IFormFile file,string? Pc)
        {
            Logger.LogInformation("上传图片成功");
            var n = Guid.NewGuid();
            var files = "wwwroot/Img/" + n + file.FileName;

            using (FileStream fs = new FileStream(files, FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            var path = "http://localhost:27167/Img/" + n + file.FileName;
            return Ok(path);
        }

        [HttpPost]
        public async Task<APIResult<int>> EnterCreate(EnterCreateCommand request )
        {
            Logger.LogInformation("新增企业信息成功");
            return await Mediator.Send(request);

        }
        [HttpGet]
        public async Task<APIResult<EnterClass>> EnterQuery([FromQuery]EnterQueryCommand request )
        {
            Logger.LogInformation("反填企业信息信息成功");
            return await Mediator.Send(request);
        }
        [HttpPost]
        public async Task<APIResult<int>> SlantureCreate(SlaughterCreateCommand request )
        {
            Logger.LogInformation("新增屠宰信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<Slaughter>> SlantureQuery([FromQuery]SlaughterFtCommand request )
        {
            Logger.LogInformation("反填屠宰信息信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<List<SlanDTO>>> SlantBossQuery([FromQuery]SlanBossQueryCommand request )
        {
            Logger.LogInformation("查询省份信息信息成功");
            return await Mediator.Send(request);
        }
        [HttpPost]
        public async Task<APIResult<int>> BossCreate(SlanBossCreateCommand request )
        {
            Logger.LogInformation("新增屠宰企业信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<SlanghterBoss>> BossQuery([FromQuery]BossFtCommand request )
        {
            Logger.LogInformation("查询屠宰企业信息成功");
            return await Mediator.Send(request);
        }

        [HttpPost]
        public async Task<APIResult<int>> OverCreate(OverTimeCreateCommand request )
        {
            Logger.LogInformation("新增深加工信息信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<OvertimeClass>> OverTimeQuery([FromQuery]OverTimeQueryCommand request )
        {
            Logger.LogInformation("反填深加工信息成功");
            return await Mediator.Send(request);
        }
        [HttpPost]
        public async Task<APIResult<int>> ProceCreate(ProcessingCreateCommand request )
        {
            Logger.LogInformation("新增深加工企业信息信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<Processing>> ProcssQuery([FromQuery]ProcessingFtCommand request )
        {
            Logger.LogInformation("反填深加工企业信息成功");
            return await Mediator.Send(request);
        }
        [HttpPost]
        public async Task<APIResult<int>> ImgInforCreate(ImgInforCommand request )
        {
            Logger.LogInformation("新增图片信息成功");
            return await Mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIResult<List<ImgInfor>>> ImgQuery([FromQuery]ImgInforQueryCommand request )
        {
            Logger.LogInformation("反填图片信息成功");
            return await Mediator.Send(request);
        }
    }
}
